package com.syscom.server.qc.cacheManager;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import com.syscom.frmcommon.util.ArithUtil;
import com.syscom.safe.cache.SafeCacheException;
import com.syscom.safe.cache.SafeCacheManager;
import com.syscom.safe.cache.SafeCacheVo;
import com.syscom.sar.server.constant.UnusualTradeConstant;
import com.syscom.sar.server.rsk.vo.SarNBST;
import com.syscom.server.cache.safeCache.AccuNBST4Cache;
import com.syscom.server.cache.safeCache.vo.AccuNBST4CacheVo;
import com.syscom.server.constant.CacheConstant;
import com.syscom.shared.constant.CodeConstant;
import com.syscom.shared.constant.LogConstant;
import com.syscom.shared.os.emf.ExtendedOrderType;

/**
 * @author Jean
 */
public class AccuNBST4CacheManager {
	@SuppressWarnings("unused")
	private transient static final String mark = "10BCC85DDC54DDF27A18E78A2AA7EB50A27C9789E7CDBE9FD4DD9C9DC56D7247A585625B8AE77885";
	private static Logger mLogger = Logger.getLogger(LogConstant.SAR_SERVER_LOGGER);
	private static AccuNBST4CacheManager instance = new AccuNBST4CacheManager();
	
	private AccuNBST4Cache mNBST4Cache = null;
	
	public static AccuNBST4CacheManager getInstance() { return instance; }
	
	private AccuNBST4CacheManager() {
		mNBST4Cache = (AccuNBST4Cache) SafeCacheManager.getInstance().getCache(CacheConstant.ACCU_NBST_4);
	}
	
	public SafeCacheVo getAccuNBST(char cLevel, String sKey) {
		try {
			AccuNBST4CacheVo accuNBSTVo = (AccuNBST4CacheVo) mNBST4Cache.getVoForReading(sKey);
			return accuNBSTVo;
		}
		catch (SafeCacheException e) {
			if (mLogger.isEnabledFor(Level.ERROR)) {
				mLogger.log(Level.ERROR, e.getMessage(), e);
        	}
		}
		
		return null;
	}

	public double getAllMarginIncAmt(char cLevel, String sBranchId, String sIvsAcctCd, String sProdId) {
		String sKey1 = AccuNBST4CacheVo.getKeyString(sProdId, ExtendedOrderType.AGENCY_FINANCING.getEnumerationID());
		String sKey3 = AccuNBST4CacheVo.getKeyString(sProdId, ExtendedOrderType.FINANCING.getEnumerationID());
		
		double dIncAmt1 = 0;
		double dIncAmt3 = 0;
		
		AccuNBST4CacheVo accuNBSTVo1 = null;
		AccuNBST4CacheVo accuNBSTVo3 = null;
		try {
			accuNBSTVo1 = (AccuNBST4CacheVo) mNBST4Cache.getVoForReading(sKey1);
			accuNBSTVo3 = (AccuNBST4CacheVo) mNBST4Cache.getVoForReading(sKey3);
			
			if (accuNBSTVo1 != null) dIncAmt1 = accuNBSTVo1.getIncAmt();
			if (accuNBSTVo3 != null) dIncAmt3 = accuNBSTVo3.getIncAmt();
		}
		catch (SafeCacheException e) {
			if (mLogger.isEnabledFor(Level.ERROR)) { mLogger.log(Level.ERROR, e.getMessage(), e); }
		}
		finally {
			releaseAccuRuleVoFromReading(cLevel, accuNBSTVo1);
			releaseAccuRuleVoFromReading(cLevel, accuNBSTVo3);
		}
		
		double dMarginIncAmt = ArithUtil.add(dIncAmt1, dIncAmt3);
		
		return dMarginIncAmt;
	}

	public double getAllMarginDecAmt(char cLevel, String sBranchId, String sIvsAcctCd, String sProdId) {
		String sKey1 = AccuNBST4CacheVo.getKeyString(sProdId, ExtendedOrderType.AGENCY_FINANCING.getEnumerationID());
		String sKey3 = AccuNBST4CacheVo.getKeyString(sProdId, ExtendedOrderType.FINANCING.getEnumerationID());
		
		double dDecAmt1 = 0;
		double dDecAmt3 = 0;

		AccuNBST4CacheVo accuNBSTVo1 = null;
		AccuNBST4CacheVo accuNBSTVo3 = null;
		try {
			accuNBSTVo1 = (AccuNBST4CacheVo) mNBST4Cache.getVoForReading(sKey1);
			accuNBSTVo3 = (AccuNBST4CacheVo) mNBST4Cache.getVoForReading(sKey3);
			
			if (accuNBSTVo1 != null) dDecAmt1 = accuNBSTVo1.getDecAmt();
			if (accuNBSTVo3 != null) dDecAmt3 = accuNBSTVo3.getDecAmt();
		}
		catch (SafeCacheException e) {
			if (mLogger.isEnabledFor(Level.ERROR)) { mLogger.log(Level.ERROR, e.getMessage(), e); }
		}
		finally {
			releaseAccuRuleVoFromReading(cLevel, accuNBSTVo1);
			releaseAccuRuleVoFromReading(cLevel, accuNBSTVo3);
		}
		
		double dMarginDecAmt = ArithUtil.add(dDecAmt1, dDecAmt3);
		
		return dMarginDecAmt;
	}

	public double getAllShortIncAmt(char cLevel, String sBranchId, String sIvsAcctCd, String sProdId) {
		String sKey2 = AccuNBST4CacheVo.getKeyString(sProdId, ExtendedOrderType.AGENCY_BEARISH.getEnumerationID());
		String sKey4 = AccuNBST4CacheVo.getKeyString(sProdId, ExtendedOrderType.BEARISH.getEnumerationID());
		
		double dIncAmt2 = 0;
		double dIncAmt4 = 0;
		
		AccuNBST4CacheVo accuNBSTVo2 = null;
		AccuNBST4CacheVo accuNBSTVo4 = null;
		try {
			accuNBSTVo2 = (AccuNBST4CacheVo) mNBST4Cache.getVoForReading(sKey2);
			accuNBSTVo4 = (AccuNBST4CacheVo) mNBST4Cache.getVoForReading(sKey4);
			
			if (accuNBSTVo2 != null) dIncAmt2 = accuNBSTVo2.getIncAmt();
			if (accuNBSTVo4 != null) dIncAmt4 = accuNBSTVo4.getIncAmt();
		}
		catch (SafeCacheException e) {
			if (mLogger.isEnabledFor(Level.ERROR)) { mLogger.log(Level.ERROR, e.getMessage(), e); }
		}
		finally {
			releaseAccuRuleVoFromReading(cLevel, accuNBSTVo2);
			releaseAccuRuleVoFromReading(cLevel, accuNBSTVo4);
		}
		
		double dShortIncAmt = ArithUtil.add(dIncAmt2, dIncAmt4);
		
		return dShortIncAmt;
	}

	public double getAllShortDecAmt(char cLevel, String sBranchId, String sIvsAcctCd, String sProdId) {
		String sKey2 = AccuNBST4CacheVo.getKeyString(sProdId, ExtendedOrderType.AGENCY_BEARISH.getEnumerationID());
		String sKey4 = AccuNBST4CacheVo.getKeyString(sProdId, ExtendedOrderType.BEARISH.getEnumerationID());
		
		double dDecAmt2 = 0;
		double dDecAmt4 = 0;
		
		AccuNBST4CacheVo accuNBSTVo2 = null;
		AccuNBST4CacheVo accuNBSTVo4 = null;
		try {
			accuNBSTVo2 = (AccuNBST4CacheVo) mNBST4Cache.getVoForReading(sKey2);
			accuNBSTVo4 = (AccuNBST4CacheVo) mNBST4Cache.getVoForReading(sKey4);
			
			if (accuNBSTVo2 != null) dDecAmt2 = accuNBSTVo2.getDecAmt();
			if (accuNBSTVo4 != null) dDecAmt4 = accuNBSTVo4.getDecAmt();
		}
		catch (SafeCacheException e) {
			if (mLogger.isEnabledFor(Level.ERROR)) { mLogger.log(Level.ERROR, e.getMessage(), e); }
		}
		finally {
			releaseAccuRuleVoFromReading(cLevel, accuNBSTVo2);
			releaseAccuRuleVoFromReading(cLevel, accuNBSTVo4);
		}
		
		double dShortDecAmt = ArithUtil.add(dDecAmt2, dDecAmt4);
		
		return dShortDecAmt;
	}

	public double getAllNonConMarginIncAmt(char cLevel, String sBranchId, String sIvsAcctCd, String sProdId) {
		String sKey1 = AccuNBST4CacheVo.getKeyString(sProdId, ExtendedOrderType.AGENCY_FINANCING.getEnumerationID());
		String sKey3 = AccuNBST4CacheVo.getKeyString(sProdId, ExtendedOrderType.FINANCING.getEnumerationID());
		
		double dIncAmt1 = 0;
		double dIncAmt3 = 0;
		
		AccuNBST4CacheVo accuNBSTVo1 = null;
		AccuNBST4CacheVo accuNBSTVo3 = null;
		try {
			accuNBSTVo1 = (AccuNBST4CacheVo) mNBST4Cache.getVoForReading(sKey1);
			accuNBSTVo3 = (AccuNBST4CacheVo) mNBST4Cache.getVoForReading(sKey3);
			
			if (accuNBSTVo1 != null) dIncAmt1 = accuNBSTVo1.getNonConIncAmt();
			if (accuNBSTVo3 != null) dIncAmt3 = accuNBSTVo3.getNonConIncAmt();
		}
		catch (SafeCacheException e) {
			if (mLogger.isEnabledFor(Level.ERROR)) { mLogger.log(Level.ERROR, e.getMessage(), e); }
		}
		finally {
			releaseAccuRuleVoFromReading(cLevel, accuNBSTVo1);
			releaseAccuRuleVoFromReading(cLevel, accuNBSTVo3);
		}
		
		double dMarginIncAmt = ArithUtil.add(dIncAmt1, dIncAmt3);
		
		return dMarginIncAmt;
	}

	public double getAllNonConMarginDecAmt(char cLevel, String sBranchId, String sIvsAcctCd, String sProdId) {
		String sKey1 = AccuNBST4CacheVo.getKeyString(sProdId, ExtendedOrderType.AGENCY_FINANCING.getEnumerationID());
		String sKey3 = AccuNBST4CacheVo.getKeyString(sProdId, ExtendedOrderType.FINANCING.getEnumerationID());
		
		double dDecAmt1 = 0;
		double dDecAmt3 = 0;
		
		AccuNBST4CacheVo accuNBSTVo1 = null;
		AccuNBST4CacheVo accuNBSTVo3 = null;
		try {
			accuNBSTVo1 = (AccuNBST4CacheVo) mNBST4Cache.getVoForReading(sKey1);
			accuNBSTVo3 = (AccuNBST4CacheVo) mNBST4Cache.getVoForReading(sKey3);
			
			if (accuNBSTVo1 != null) dDecAmt1 = accuNBSTVo1.getNonConDecAmt();
			if (accuNBSTVo3 != null) dDecAmt3 = accuNBSTVo3.getNonConDecAmt();
		}
		catch (SafeCacheException e) {
			if (mLogger.isEnabledFor(Level.ERROR)) { mLogger.log(Level.ERROR, e.getMessage(), e); }
		}
		finally {
			releaseAccuRuleVoFromReading(cLevel, accuNBSTVo1);
			releaseAccuRuleVoFromReading(cLevel, accuNBSTVo3);
		}
		
		double dMarginDecAmt = ArithUtil.add(dDecAmt1, dDecAmt3);
		
		return dMarginDecAmt;
	}

	public double getAllNonConShortIncAmt(char cLevel, String sBranchId, String sIvsAcctCd, String sProdId) {
		String sKey2 = AccuNBST4CacheVo.getKeyString(sProdId, ExtendedOrderType.AGENCY_BEARISH.getEnumerationID());
		String sKey4 = AccuNBST4CacheVo.getKeyString(sProdId, ExtendedOrderType.BEARISH.getEnumerationID());
		
		double dIncAmt2 = 0;
		double dIncAmt4 = 0;

		AccuNBST4CacheVo accuNBSTVo2 = null;
		AccuNBST4CacheVo accuNBSTVo4 = null;
		try {
			accuNBSTVo2 = (AccuNBST4CacheVo) mNBST4Cache.getVoForReading(sKey2);
			accuNBSTVo4 = (AccuNBST4CacheVo) mNBST4Cache.getVoForReading(sKey4);
			
			if (accuNBSTVo2 != null) dIncAmt2 = accuNBSTVo2.getNonConIncAmt();
			if (accuNBSTVo4 != null) dIncAmt4 = accuNBSTVo4.getNonConIncAmt();
		}
		catch (SafeCacheException e) {
			if (mLogger.isEnabledFor(Level.ERROR)) { mLogger.log(Level.ERROR, e.getMessage(), e); }
		}
		finally {
			releaseAccuRuleVoFromReading(cLevel, accuNBSTVo2);
			releaseAccuRuleVoFromReading(cLevel, accuNBSTVo4);
		}
		
		double dShortIncAmt = ArithUtil.add(dIncAmt2, dIncAmt4);
		
		return dShortIncAmt;
	}

	public double getAllNonConShortDecAmt(char cLevel, String sBranchId, String sIvsAcctCd, String sProdId) {
		String sKey2 = AccuNBST4CacheVo.getKeyString(sProdId, ExtendedOrderType.AGENCY_BEARISH.getEnumerationID());
		String sKey4 = AccuNBST4CacheVo.getKeyString(sProdId, ExtendedOrderType.BEARISH.getEnumerationID());
		
		double dDecAmt2 = 0;
		double dDecAmt4 = 0;

		AccuNBST4CacheVo accuNBSTVo2 = null;
		AccuNBST4CacheVo accuNBSTVo4 = null;
		try {
			accuNBSTVo2 = (AccuNBST4CacheVo) mNBST4Cache.getVoForReading(sKey2);
			accuNBSTVo4 = (AccuNBST4CacheVo) mNBST4Cache.getVoForReading(sKey4);
			
			if (accuNBSTVo2 != null) dDecAmt2 = accuNBSTVo2.getNonConDecAmt();
			if (accuNBSTVo4 != null) dDecAmt4 = accuNBSTVo4.getNonConDecAmt();
		}
		catch (SafeCacheException e) {
			if (mLogger.isEnabledFor(Level.ERROR)) { mLogger.log(Level.ERROR, e.getMessage(), e); }
		}
		finally {
			releaseAccuRuleVoFromReading(cLevel, accuNBSTVo2);
			releaseAccuRuleVoFromReading(cLevel, accuNBSTVo4);
		}
		
		double dShortDecAmt = ArithUtil.add(dDecAmt2, dDecAmt4);
		
		return dShortDecAmt;
	}

	public double getAllLoanIncAmt(char cLevel, String sBranchId, String sIvsAcctCd, String sProdId) {
		String sKey5 = AccuNBST4CacheVo.getKeyString(sProdId, ExtendedOrderType.BEARISH_C5.getEnumerationID());
		String sKey6 = AccuNBST4CacheVo.getKeyString(sProdId, ExtendedOrderType.BEARISH_C6.getEnumerationID());
		
		double dIncAmt5 = 0;
		double dIncAmt6 = 0;
		
		AccuNBST4CacheVo accuNBSTVo5 = null;
		AccuNBST4CacheVo accuNBSTVo6 = null;
		try {
			accuNBSTVo5 = (AccuNBST4CacheVo) mNBST4Cache.getVoForReading(sKey5);
			accuNBSTVo6 = (AccuNBST4CacheVo) mNBST4Cache.getVoForReading(sKey6);
			
			if (accuNBSTVo5 != null) dIncAmt5 = accuNBSTVo5.getIncAmt();
			if (accuNBSTVo6 != null) dIncAmt6 = accuNBSTVo6.getIncAmt();
		}
		catch (SafeCacheException e) {
			if (mLogger.isEnabledFor(Level.ERROR)) { mLogger.log(Level.ERROR, e.getMessage(), e); }
		}
		finally {
			releaseAccuRuleVoFromReading(cLevel, accuNBSTVo5);
			releaseAccuRuleVoFromReading(cLevel, accuNBSTVo6);
		}
		
		double dShortIncAmt = ArithUtil.add(dIncAmt5, dIncAmt6);
		
		return dShortIncAmt;
	}

	public double getAllLoanDecAmt(char cLevel, String sBranchId, String sIvsAcctCd, String sProdId) {
		String sKey5 = AccuNBST4CacheVo.getKeyString(sProdId, ExtendedOrderType.BEARISH_C5.getEnumerationID());
		String sKey6 = AccuNBST4CacheVo.getKeyString(sProdId, ExtendedOrderType.BEARISH_C6.getEnumerationID());
		
		double dDecAmt5 = 0;
		double dDecAmt6 = 0;
		
		AccuNBST4CacheVo accuNBSTVo5 = null;
		AccuNBST4CacheVo accuNBSTVo6 = null;
		try {
			accuNBSTVo5 = (AccuNBST4CacheVo) mNBST4Cache.getVoForReading(sKey5);
			accuNBSTVo6 = (AccuNBST4CacheVo) mNBST4Cache.getVoForReading(sKey6);
			
			if (accuNBSTVo5 != null) dDecAmt5 = accuNBSTVo5.getDecAmt();
			if (accuNBSTVo6 != null) dDecAmt6 = accuNBSTVo6.getDecAmt();
		}
		catch (SafeCacheException e) {
			if (mLogger.isEnabledFor(Level.ERROR)) { mLogger.log(Level.ERROR, e.getMessage(), e); }
		}
		finally {
			releaseAccuRuleVoFromReading(cLevel, accuNBSTVo5);
			releaseAccuRuleVoFromReading(cLevel, accuNBSTVo6);
		}
		
		double dShortDecAmt = ArithUtil.add(dDecAmt5, dDecAmt6);
		
		return dShortDecAmt;
	}

	public long getAllLoanIncShare(char cLevel, String sBranchId, String sIvsAcctCd, String sProdId) {
		String sKey5 = AccuNBST4CacheVo.getKeyString(sProdId, ExtendedOrderType.BEARISH_C5.getEnumerationID());
		String sKey6 = AccuNBST4CacheVo.getKeyString(sProdId, ExtendedOrderType.BEARISH_C6.getEnumerationID());
		
		long lIncShare5 = 0;
		long lIncShare6 = 0;
		
		AccuNBST4CacheVo accuNBSTVo5 = null;
		AccuNBST4CacheVo accuNBSTVo6 = null;
		try {
			accuNBSTVo5 = (AccuNBST4CacheVo) mNBST4Cache.getVoForReading(sKey5);
			accuNBSTVo6 = (AccuNBST4CacheVo) mNBST4Cache.getVoForReading(sKey6);
			
			if (accuNBSTVo5 != null) lIncShare5 = accuNBSTVo5.getIncShare();
			if (accuNBSTVo6 != null) lIncShare6 = accuNBSTVo6.getIncShare();
		}
		catch (SafeCacheException e) {
			if (mLogger.isEnabledFor(Level.ERROR)) { mLogger.log(Level.ERROR, e.getMessage(), e); }
		}
		finally {
			releaseAccuRuleVoFromReading(cLevel, accuNBSTVo5);
			releaseAccuRuleVoFromReading(cLevel, accuNBSTVo6);
		}
		
		long lLoanIncShare = lIncShare5 + lIncShare6;
		
		return lLoanIncShare;
	}

	public long getAllLoanDecShare(char cLevel, String sBranchId, String sIvsAcctCd, String sProdId) {
		String sKey5 = AccuNBST4CacheVo.getKeyString(sProdId, ExtendedOrderType.BEARISH_C5.getEnumerationID());
		String sKey6 = AccuNBST4CacheVo.getKeyString(sProdId, ExtendedOrderType.BEARISH_C6.getEnumerationID());
		
		long lDecShare5 = 0;
		long lDecShare6 = 0;
		
		AccuNBST4CacheVo accuNBSTVo5 = null;
		AccuNBST4CacheVo accuNBSTVo6 = null;
		try {
			accuNBSTVo5 = (AccuNBST4CacheVo) mNBST4Cache.getVoForReading(sKey5);
			accuNBSTVo6 = (AccuNBST4CacheVo) mNBST4Cache.getVoForReading(sKey6);
			
			if (accuNBSTVo5 != null) lDecShare5 = accuNBSTVo5.getDecShare();
			if (accuNBSTVo6 != null) lDecShare6 = accuNBSTVo6.getDecShare();
		}
		catch (SafeCacheException e) {
			if (mLogger.isEnabledFor(Level.ERROR)) { mLogger.log(Level.ERROR, e.getMessage(), e); }
		}
		finally {
			releaseAccuRuleVoFromReading(cLevel, accuNBSTVo5);
			releaseAccuRuleVoFromReading(cLevel, accuNBSTVo6);
		}
		
		long lLoanDecAmt = lDecShare5 + lDecShare6;
		
		return lLoanDecAmt;
	}
	
	public void releaseAccuRuleVoFromReading(char cLevel, SafeCacheVo accuNBSTVo) {
		if (accuNBSTVo == null) return;
		
		try {
			mNBST4Cache.releaseVoFromReading(accuNBSTVo);
		}
		catch (SafeCacheException e) {
			if (mLogger.isEnabledFor(Level.ERROR)) {
				mLogger.log(Level.ERROR, e.getMessage(), e);
        	}
		}
	}
	
	public void updateAccuNBST(SarNBST nbstVo) throws Exception {
		makeUpdAccuNBST(CodeConstant.LEVEL_INVESTOR, nbstVo);
		makeUpdAccuNBST(CodeConstant.LEVEL_AGENT, nbstVo);
		makeUpdAccuNBST(CodeConstant.LEVEL_BRANCH, nbstVo);
	}
	
	private void makeUpdAccuNBST(char cLevel, SarNBST nbstVo) {
		StringBuffer sb = new StringBuffer();
		String sNBSTKey   = nbstVo.getTradeNumber();
		String sProdId    = nbstVo.getProdId();
		int    iOrderTp   = nbstVo.getOrderTp();
		
		AccuNBST4CacheVo updAccuNBSTVo = null;
		try {
			AccuNBST4CacheVo newAccuNBSTVo = new AccuNBST4CacheVo(String.valueOf(cLevel), sProdId, iOrderTp, 0, 0, 0, 0, 0, 0, 0, 0);
			newAccuNBSTVo = calAccuNBST1(nbstVo, newAccuNBSTVo);
			
			if (!mNBST4Cache.insertVoIfNotExist(newAccuNBSTVo)) {
				String sKey = AccuNBST4CacheVo.getKeyString(sProdId, iOrderTp);
				updAccuNBSTVo = (AccuNBST4CacheVo) mNBST4Cache.getVoForUpdating(sKey);
				if (updAccuNBSTVo != null) {
					sb.append("{<Original>").append(updAccuNBSTVo.getVoDataString()).append("}, ");
					
					updAccuNBSTVo = calAccuNBST1(nbstVo, updAccuNBSTVo);
					
					sb.append("{<Current>>").append(updAccuNBSTVo.getVoDataString()).append("}");
					mLogger.log(Level.INFO, "<" + sNBSTKey + "><AccuNBST Info> " + sb.toString());
				}
			}
			else {
				sb.append("{<New>").append(newAccuNBSTVo.getVoDataString()).append("}");
				mLogger.log(Level.INFO, "<" + sNBSTKey + "><AccuNBST Info> " + sb.toString());
			}
		}
		catch (SafeCacheException e) {
			if (mLogger.isEnabledFor(Level.ERROR)) { mLogger.log(Level.ERROR, e.getMessage(), e); }
		}
		finally {
			try {
				if (updAccuNBSTVo != null) { mNBST4Cache.releaseVoFromUpdating(updAccuNBSTVo); }
			} 
			catch (SafeCacheException e) {
				if (mLogger.isEnabledFor(Level.ERROR)) { mLogger.log(Level.ERROR, e.getMessage(), e); }
			}
		}
	}
	
	private AccuNBST4CacheVo calAccuNBST1(SarNBST nbstVo, AccuNBST4CacheVo accuNBSTVo) {
		boolean isConstiStk  = false;
		// TODO
//		ProductCacheVo prodVo = null;
//		try {
//			prodVo = ProductCacheManager.getInstance().getProductCacheVo(nbstVo.getProdId());
//			if (prodVo != null) { isConstiStk = prodVo.getConstituentStk(); }
//		}
//		finally {
//			ProductCacheManager.getInstance().releaseProductCacheVoForReading(prodVo);
//		}
		
		int iMdfCd    = nbstVo.getModifyCode();
		int iIncDecTp = nbstVo.getIncDecTp();
		
		double dNBSTAmt   = nbstVo.getAmt();
		long   lNBSTShare = nbstVo.getShares();
		
		double dCurrentAmt = 0;
		long   lCurrentShare = 0;
		
		if (iMdfCd == UnusualTradeConstant.NBST_MODIFY_CODE_ADD) {
			if (iIncDecTp == UnusualTradeConstant.INCDEC_TP_INCREASE) {
				double dOrgAmt = accuNBSTVo.getIncAmt();
				dCurrentAmt = ArithUtil.add(dOrgAmt, dNBSTAmt);
				accuNBSTVo.setIncAmt(dCurrentAmt);
				
				long lOrgShare = accuNBSTVo.getIncShare();
				lCurrentShare = lOrgShare + lNBSTShare;
				accuNBSTVo.setIncShare(lCurrentShare);
				
				if (!isConstiStk) {
					double dOrgNonConAmt = accuNBSTVo.getNonConIncAmt();
					dCurrentAmt = ArithUtil.add(dOrgNonConAmt, dNBSTAmt);
					accuNBSTVo.setNonConIncAmt(dCurrentAmt);
					
					long lOrgNonConShare = accuNBSTVo.getNonConIncShare();
					lCurrentShare = lOrgNonConShare + lNBSTShare;
					accuNBSTVo.setNonConIncShare(lCurrentShare);
				}
			}
			else if (iIncDecTp == UnusualTradeConstant.INCDEC_TP_DECREASE) {
				double dOrgAmt = accuNBSTVo.getDecAmt();
				dCurrentAmt = ArithUtil.add(dOrgAmt, dNBSTAmt);
				accuNBSTVo.setDecAmt(dCurrentAmt);
				
				long lOrgShare = accuNBSTVo.getDecShare();
				lCurrentShare = lOrgShare + lNBSTShare;
				accuNBSTVo.setDecShare(lCurrentShare);
				
				if (!isConstiStk) {
					double dOrgNonConAmt = accuNBSTVo.getNonConDecAmt();
					dCurrentAmt = ArithUtil.add(dOrgNonConAmt, dNBSTAmt);
					accuNBSTVo.setNonConDecAmt(dCurrentAmt);
					
					long lOrgNonConShare = accuNBSTVo.getNonConDecShare();
					lCurrentShare = lOrgNonConShare + lNBSTShare;
					accuNBSTVo.setNonConDecShare(lCurrentShare);
				}
			}
		}
		else if (iMdfCd == UnusualTradeConstant.NBST_MODIFY_CODE_DEL) {
			if (iIncDecTp == UnusualTradeConstant.INCDEC_TP_INCREASE) {
				double dOrgAmt = accuNBSTVo.getIncAmt();
				dCurrentAmt = ArithUtil.sub(dOrgAmt, dNBSTAmt);
				accuNBSTVo.setIncAmt(dCurrentAmt);
				
				long lOrgShare = accuNBSTVo.getIncShare();
				lCurrentShare = lOrgShare - lNBSTShare;
				accuNBSTVo.setIncShare(lCurrentShare);
				
				if (!isConstiStk) {
					double dOrgNonConAmt = accuNBSTVo.getNonConIncAmt();
					dCurrentAmt = ArithUtil.sub(dOrgNonConAmt, dNBSTAmt);
					accuNBSTVo.setNonConIncAmt(dCurrentAmt);
					
					long lOrgNonConShare = accuNBSTVo.getNonConIncShare();
					lCurrentShare = lOrgNonConShare - lNBSTShare;
					accuNBSTVo.setNonConIncShare(lCurrentShare);
				}
			}
			else if (iIncDecTp == UnusualTradeConstant.INCDEC_TP_DECREASE) {
				double dOrgAmt = accuNBSTVo.getDecAmt();
				dCurrentAmt = ArithUtil.sub(dOrgAmt, dNBSTAmt);
				accuNBSTVo.setDecAmt(dCurrentAmt);
				
				long lOrgShare = accuNBSTVo.getDecShare();
				lCurrentShare = lOrgShare - lNBSTShare;
				accuNBSTVo.setDecShare(lCurrentShare);
				
				if (!isConstiStk) {
					double dOrgNonConAmt = accuNBSTVo.getNonConDecAmt();
					dCurrentAmt = ArithUtil.sub(dOrgNonConAmt, dNBSTAmt);
					accuNBSTVo.setNonConDecAmt(dCurrentAmt);
					
					long lOrgNonConShare = accuNBSTVo.getNonConDecShare();
					lCurrentShare = lOrgNonConShare - lNBSTShare;
					accuNBSTVo.setNonConDecShare(lCurrentShare);
				}
			}
		}
		
		return accuNBSTVo;
	}

}
